<?php

class Control_User_HeaderInfo extends QUI_Control_Abstract
{
    function render()
    {
        $user = Q::registry('app')->currentUser();

        if (empty($user))
        {
            $login_url = Q::ini('appini/passport/login_url');
            $register_url = Q::ini('appini/passport/register_url');

            $out = <<<EOT

<ul id="user_info">
  <li><a href="{$login_url}" class="login">登录</a></li>
  <li><a href="{$register_url}" class="register">加入社区</a></li>
</ul>


EOT;

        }
        else
        {
            $logout_url = url('default/logout');
            $userinfo_url = Q::ini('appini/passport/profile_url');
            if (strpos($userinfo_url, '%UID%') > 0)
            {
                $userinfo_url = str_replace('%UID%', $user['id'], $userinfo_url);
            }
            $out = <<<EOT

<ul id="user_info">
  <li><a href="{$userinfo_url}" class="profile">{$user['username']}</a>, 欢迎访问社区.&nbsp;&nbsp;<a href="{$logout_url}" class="logout">注销</a></li>
</ul>


EOT;
        }

        return $out;
    }
}

